// pages/electricdetails/electricdetails.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    detailShow:true,
    exchangeShow:false,
    detailsList:[
     
    ],
    exchangeList:[

    ]
  },
  changetabDetails:function(){
    var vm = this;
    var userid = getApp().globalData.openid;
    if(userid){
          wx.request({
      url: getApp().globalData.baseUrl + '/wago/jifen/findObtainMingxi',
      method:'post',
      data: {
        userid
      },
      success: function (res) {
        var datas = res.data.data;
        for (var i in datas) {
          datas[i].changetime = vm.format22(datas[i].changetime)
      }
        vm.setData({
          detailsList:datas
        })
      }
    })
    this.setData({
      detailShow:true,
      exchangeShow:false
    })
    }else{
      wx.showToast({
        title: '请先登录',
        duration: 2000,
        icon: 'none'
      });
    }

  },
  changetabExchange:function(){
    var vm = this;
    var userid = getApp().globalData.openid;
        if(userid){
          wx.request({
      url: getApp().globalData.baseUrl + '/wago/jifen/findExchangeMingxi',
      method:'post',
      data: {
        userid
      },
      success: function (res) {
        var datas = res.data.data;
        for (var i in datas) {
          datas[i].changetime = vm.format22(datas[i].changetime)
      }
        vm.setData({
          exchangeList:datas
        })
      }
    })
    this.setData({
      detailShow:false,
      exchangeShow:true
    })
    }else{
      wx.showToast({
        title: '请先登录',
        duration: 2000,
        icon: 'none'
      });
    }

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.changetabDetails();
    this.doHandleYear();
    this.getpersonEle();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  
doHandleYear() {
  var myDate = new Date();
  var tYear = myDate.getFullYear();
  if(tYear > 2020){
      this.setData({
    nextY:tYear+1
  })
  }else{
    this.setData({
      nextY:2022
    })
  }

},
chosseto:function(){
  wx.switchTab({
    url: '/pages/scoreStore/scoreStore',
    });
},
getpersonEle:function(){
  var that = this;
  wx.request({
    url: getApp().globalData.baseUrl + '/wago/jifen/selectById',
    data: {
      userid:getApp().globalData.openid
    },
    method: 'POST', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
    // header: {}, // 设置请求的 header
    success: function(res){
      // console.log('海报',res.data.data)
      // success
      if(res.data.flag){
        that.setData({
          eledata:res.data.data,
        })
        console.log('积分',that.data.eledata)
      }
    },
    fail: function() {
      // fail
    },
    complete: function() {
      // complete
    }
  })
},
  add0: function (m) { return m < 10 ? '0' + m : m },
  format22: function (shijianchuo) {
    //shijianchuo是整数，否则要parseInt转换
    var time = new Date(shijianchuo);
    var y = time.getFullYear();
    var m = time.getMonth() + 1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    return  y + '-' + this.add0(m) + '-' + this.add0(d)+ ' ' + this.add0(h)+ ':' + this.add0(mm)

  },
})